home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MACD 5
/
MACD 5.bin
/
workbench
/
tools
/
czesc_1
/
cookie
/
cookhash_old.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-04-19
|
1KB
|
74 lines
/* cookhash - read a sayings file and generate an index file
* by Karl Lehenbauer (karl@sugar.uu.net, uunet!sugar!karl)
* cookhash.c 1.1 1/12/89
*/
/*
* 1995-04-19 [JöG] Allowed comments after the "%%"
* didn't bump revision though
*
*
*
*/
#include <stdio.h>
#include <stdlib.h>
#define YES 1
#define NO 0
#define METACHAR '%'
main(int argc,char *argv[])
{
int c, sawmeta=0;
long charpos = 0;
if (argc != 1)
{
fprintf(stderr,"usage: cookhash <cookiefile >hashfile\n");
exit(1);
}
/* write out the "address" of the first cookie */
puts("000000");
/* read the cookie until the end,
* whenever the end-of-cookie ("%%") sequence is found,
* the "address" (file position) of the first byte following
* it (start of next cookie) is written to the index (hash) file
*/
while ((c = getchar()) != EOF)
{
if (c == METACHAR)
{
if (sawmeta)
{
/* Now, allow for comment after the "%%" */
while((c=getchar())!='\n')
{
if(c==EOF)
{ exit(2);
}
charpos++;
}
charpos++; /* Compensate for uncounted '\n' */
printf("%06lx\n",charpos+1);
sawmeta = NO;
}
else
sawmeta = YES;
}
else
sawmeta = NO;
charpos++;
}
exit(0);
}
/* end of cookhash.c */